insert overwrite table jms_dwd.dwd_tab_report_errorbagging_detail_base_dt partition (dt)
select scan_time,
       site_code,
       site_name,
       proxy_area_code,
       proxy_area_name,
       franchisees_code,
       franchisees_name,
       bagcode,
       billcode,
       shouldodm,
       realodm,
       if(scanuser is not null,split(scanuser,'/')[1],null) as scan_user_code,
       if(scanuser is not null,split(scanuser,'/')[0],null) as scan_user_name,
       remark1 as bill_source,
       remark2,
       date_format(create_time,'yyyy-MM-dd HH:mm:ss') as create_time,
       cast(to_date(scan_time) as string)  as dt
from jms_ods.tab_report_errorbagging_detail
where dt between date_add('{{ execution_date | cst_ds }}', -3)
and '{{ execution_date | cst_ds }}'
distribute by to_date(scan_time),1;